package com.duowan.realtime.dao.impl;

import com.duowan.realtime.dao.BaseSpringJdbcDao;
import com.duowan.realtime.dao.KpiDimStrTableNameDao;
import com.google.common.collect.ImmutableMap;
import org.springframework.dao.support.DataAccessUtils;

import java.util.Map;

/**
 * @author tangsicheng
 * @version 1.0
 * @since 1.0
 */
public class KpiDimStrTableNameDaoImpl extends BaseSpringJdbcDao implements KpiDimStrTableNameDao {

    @Override
    public String getTableNameByKpiCodeAndDimOrderStr(String kpiCode, String dimOrderStr) {
        String sql = "SELECT table_name from kpi_table_relation where kpi_code = :kpi_code and dim_str = :dim_str";
        Map<String, String> parameter = ImmutableMap.of("kpi_code", kpiCode, "dim_str", dimOrderStr);
        return DataAccessUtils.singleResult(getNamedParameterJdbcTemplate().queryForList(sql, parameter, String.class));
    }
}
